﻿using Unity.Netcode;
using UnityEngine;

public class ClientMovement : NetworkBehaviour
{
    private Rigidbody2D rb;

    public float speed = 3;

    private float horizontal;
    private float vertical;
    private Vector2 v;

    private void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    private void Update()
    {
        // 检测是否本地玩家，是否已生成
        if (!IsOwner || !IsSpawned) return;

        horizontal = Input.GetAxis("Horizontal");
        vertical = Input.GetAxis("Vertical");
        v = speed * new Vector3(horizontal, vertical, 0f).normalized;
        //rb.linearVelocity = v;
        rb.AddForce(v);
    }
}